<?php

class App_Form_User_Register extends Zend_Form
{

    public function init()
    {
        parent::init();
        $this->setMethod('post');
        $this->setAction('');
        $this->setOptions(array('class' => 'des4forms'));

        $email = new Zend_Form_Element_Text('email');
        $email->setRequired()
                ->setLabel(_('Email:'))
                ->setFilters(array(
                                  'StringToLower',
                                  'StringTrim'
                             ))
                ->addValidators(array(new Zend_Validate_EmailAddress(),
                                     new Lib_Form_Validate_DbHasNotRecord('\Catalog\User', 'email')));
        $email->setAttrib('class', 'text-input');
         $email->setAttrib('maxlength', '22');
        $email->setDecorators(array('ViewHelper'));
        $email->addErrorMessages(array(Zend_Validate_EmailAddress::INVALID => 'Input valid email.',
                                      Lib_Form_Validate_DbHasNotRecord::ERROR_RECORD_FOUND => 'Record with same email already exists.'));
        $this->addElement($email);

        $name = new Zend_Form_Element_Text('name');
        $name->setRequired()
                ->setLabel('First Name:');
        $name->setAttrib('class', 'text-input')
        ->setAttrib('maxlength', '22');
        $name->setDecorators(array('ViewHelper'));
        $name->addErrorMessage('Please, input your name.');
        $this->addElement($name);

        $lastName = new Zend_Form_Element_Text('lastName');
        $lastName->setRequired()
                ->setLabel('Last Name:');
        $lastName->setAttrib('class', 'text-input');
        $lastName->setAttrib('maxlength', '22');
        $lastName->setDecorators(array('ViewHelper'))
                ->addValidator(new Zend_Validate_StringLength(1, 32));
        $lastName->addErrorMessage('Please, input your last name. It must be less then 32 symbols.');
        $this->addElement($lastName);

        $age = new Zend_Form_Element_Text('age');
        $age->setLabel('Age:')
//                ->setRequired()
//                ->addValidator(new Zend_Validate_Digits())
                ->setAttrib('class', 'text-input')
                ->setAttrib('maxlength', '2')
                ->setDecorators(array('ViewHelper'));
//                ->setErrorMessages(array(Zend_Validate_Digits::INVALID => 'Age must contains only digits.'));
        $this->addElement($age);

        $phone = new Zend_Form_Element_Text('phone');
        $phone->setLabel('Phone:')
                ->setRequired()
                ->addValidator(new Zend_Validate_Digits())
                ->setAttrib('class', 'text-input')
                 ->setAttrib('maxlength', '22')
                ->setDecorators(array('ViewHelper'))
                ->setErrorMessages(array(Zend_Validate_Digits::INVALID => 'Phone must contains only digits.'));
        $this->addElement($phone);

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel(_('Password:'));
//                ->addValidators(array(
//                                     new Lib_Form_Validate_InputEquals('passwordConfirmation', _('Passwords do not match.'))
//                                ));
//        $password->setAttrib('class', 'text-input');
        $password->setDecorators(array('ViewHelper'));
//        $password->addValidators(array(new Zend_Validate_StringLength(0, 15)));
//        $password->addErrorMessages(array(
//                                         Zend_Validate_StringLength::INVALID => 'Password must be less then 15 symbols.',
//                                         Lib_Form_Validate_InputEquals::NOT_MATCH => 'Passwords do not match.'
//                                    ));
        $this->addElement($password);
//
//        $passwordConfirmation = new Zend_Form_Element_Password('passwordConfirmation');
//        $passwordConfirmation->setLabel(_('Password confirmation:'))
//                ->addValidator(new Lib_Form_Validate_InputEquals('password', _('Passwords do not match.')), true);
//
//        $passwordConfirmation->setAttrib('class', 'text-input');
//        $passwordConfirmation->setDecorators(array('ViewHelper'));
//        $passwordConfirmation->addErrorMessages(array(Lib_Form_Validate_InputEquals::NOT_MATCH => 'Passwords do not match.'));
//        $this->addElement($passwordConfirmation);

//        $imgDir = "../public/images/captcha/";

        // check captcha path is writeable
        //        if (is_writable($imgDir)) {
        //
        //            $captcha = new Zend_Form_Element_Captcha('captcha', array(
        //                                                                     'label' => _('Write symbols from image:'),
        //                                                                     'captcha' => 'Image',
        //                                                                     'captchaOptions' => array(
        //                                                                         'captcha' => 'Image',
        //                                                                         'wordLen' => 6,
        //                                                                         'timeout' => 300,
        //                                                                         'imgDir' => $imgDir,
        //                                                                         'imgUrl' => '/images/captcha',
        //                                                                         'suffix' => '.c.png',
        //                                                                         'font' => dirname(APPLICATION_PATH) .
        //                                                                                   "/assets/fonts/Glasten_Bold.ttf",
        //                                                                     )
        //                                                                ));
        //
        //        } else {
        //            $captcha = new Zend_Form_Element_Captcha('captcha', array(
        //                                                                     'label' => "Write symbols from image:",
        //                                                                     'captcha' => 'Figlet',
        //                                                                     'captchaOptions' => array(
        //                                                                         'wordLen' => 6,
        //                                                                         'timeout' => 300,
        //                                                                     ),
        //                                                                ));
        //        }
        //        $captcha->setAttrib('class', 'text-input');
        //        $captcha->setDecorators(array('Captcha'));
        //
        //        $this->addElement($captcha);

        $swimmer1_firstName = new Zend_Form_Element_Text('swimmer1_firstname');
        $swimmer1_firstName->setLabel('Name:')
                ->setRequired()
                ->setDecorators(array('viewHelper'));

        $this->addElement($swimmer1_firstName);

        $swimmer1_lastName = new Zend_Form_Element_Text('swimmer1_lastname');
        $swimmer1_lastName->setLabel('Name:')
                ->setRequired()
                ->setDecorators(array('viewHelper'));

        $this->addElement($swimmer1_lastName);

        $swimmer1_age = new Zend_Form_Element_Text('swimmer1_age');
        $swimmer1_age->setLabel('Name:')
                ->setRequired()
                ->addValidator(new Zend_Validate_Digits())
                ->setDecorators(array('viewHelper'));
        $this->addElement($swimmer1_age);

        $swimmer2_firstName = new Zend_Form_Element_Text('swimmer2_firstname');
        $swimmer2_firstName->setLabel('Name:')->setDecorators(array('viewHelper'));

        $this->addElement($swimmer2_firstName);

        $swimmer2_lastName = new Zend_Form_Element_Text('swimmer2_lastname');
        $swimmer2_lastName->setLabel('Name:')->setDecorators(array('viewHelper'));
        $this->addElement($swimmer2_lastName);

        $swimmer2_age = new Zend_Form_Element_Text('swimmer2_age');
        $swimmer2_age->setLabel('Name:')->setDecorators(array('viewHelper'))
                ->addValidator(new Zend_Validate_Digits());
        $this->addElement($swimmer2_age);

        $swimmer3_firstName = new Zend_Form_Element_Text('swimmer3_firstname');
        $swimmer3_firstName->setLabel('Name:')
                ->setDecorators(array('viewHelper'));

        $this->addElement($swimmer3_firstName);

        $swimmer3_lastName = new Zend_Form_Element_Text('swimmer3_lastname');
        $swimmer3_lastName->setLabel('Name:')->setDecorators(array('viewHelper'));
        $this->addElement($swimmer3_lastName);

        $swimmer3_age = new Zend_Form_Element_Text('swimmer3_age');
        $swimmer3_age->setLabel('Name:')->setDecorators(array('viewHelper'))
                ->addValidator(new Zend_Validate_Digits());
        $this->addElement($swimmer3_age);

        $submit = new Zend_Form_Element_Submit('submit', array(
                                                              'label' => _('Register')
                                                         ));
        $submit->setAttrib('class', 'button');
        $submit->setDecorators(array('ViewHelper'));
        $this->addElement($submit);

        $this->setDecorators(array(array('ViewScript', array('viewScript' => '/forms/user/register.phtml'))));

        return $this;
    }

}
